﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Prospectus
{
    public class Camera
    {
        public Vector2 Position = Vector2.Zero;
        protected float zoom = 1.0f;

        public float Zoom
        {
            get { return zoom; }
            set { zoom = Math.Max(value, 0.1f); }
        }

        public Matrix TransformMatrix
        {
            get
            {
                return Matrix.CreateTranslation(new Vector3(-Position, 0.0f)) *
                Matrix.CreateScale(new Vector3(Zoom, Zoom, 1));
            }
        }

        public void LockToTarget(Player player, int screenWidth, int screenHeight)
        {
            Position.X =
                player.Position.X + (player.texture.Width / 2) - (screenWidth / 2);
            Position.Y =
                player.Position.Y + (player.texture.Height / 2) - (screenHeight / 2);
        }

        public void ClampToArea(int width, int height)
        {
            if (Position.X > width)
                Position.X = width;
            if (Position.Y > height)
                Position.Y = height;

            if (Position.X < 0)
                Position.X = 0;
            if (Position.Y < 0)
                Position.Y = 0;
        }
    }
}
